using System.Collections.Generic;
using UnityEngine;

namespace Gj
{
    public class ShowHelper : CompareHelper
    {
        public GameObject showItem;
        public GameObject hideItem;
        public float delayTime = 0;
        public bool simple = true;
        public bool not;
        public bool isShow;
        public bool isHide;
        public List<NodeHelper> showList;
        public List<NodeHelper> hideList;
        public NodeHelper[] list;
        public AdaptiveSize adaptiveSize;
        private AnimationHelper _AnimationHelper;
        private AnimationManagerHelper _AnimationManagerHelper;

        private AnimationHelper AnimationHelper
        {
            get
            {
                if (_AnimationHelper == null) _AnimationHelper = GetComponent<AnimationHelper>();
                return _AnimationHelper;
            }
        }

        private AnimationManagerHelper AnimationManagerHelper
        {
            get
            {
                if (_AnimationManagerHelper == null) _AnimationManagerHelper = GetComponent<AnimationManagerHelper>();
                return _AnimationManagerHelper;
            }
        }

        public override void Show()
        {
            if (debug) LogTools.Log("{0} Show", gameObject.name);
            SetChildData(_data);
            if (isShow && !not) return;
            if (simple)
            {
                if (showItem != null) showItem.SetActive(true);
                if (hideItem != null) hideItem.SetActive(false);
                if (showItem == null) gameObject.SetActive(true);
            }
            else
            {
                if (isHide)
                {
                    gameObject.SetActive(true);
                    isHide = false;
                }

                if (AnimationManagerHelper != null)
                    AnimationManagerHelper.Forward();
                else if (AnimationHelper != null) AnimationHelper.Forward();
            }

            SetChildData(_data, showList);
            for (var i = 0; i < list.Length; i++) list[i].SetData(true);
            if (adaptiveSize != null) adaptiveSize.Refresh();
            isShow = true;
            isHide = false;
        }

        public override void Hide()
        {
            if (debug) LogTools.Log("{0} Hide", gameObject.name);
            if (isHide && !not) return;
            if (simple)
            {
                if (showItem != null) showItem.SetActive(false);
                if (hideItem != null) hideItem.SetActive(true);
                if (showItem == null) gameObject.SetActive(false);
            }
            else
            {
                if (AnimationManagerHelper != null)
                    AnimationManagerHelper.Backward();
                else if (AnimationHelper != null) AnimationHelper.Backward();
            }

            SetChildData(_data, hideList);
            for (var i = 0; i < list.Length; i++) list[i].SetData(false);
            if (adaptiveSize != null) adaptiveSize.Refresh();
            isHide = true;
            isShow = false;
        }
    }
}